<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/backStageBase.css}">
    <style>
        .layui-table-cell{
            height: auto !important;
        }
    </style>
</head>
<body class="layui-layout-body">
    <div id="backstage" class="layui-layout layui-layout-admin">
        <div class="layui-header layui-bg-blue" >
            <div class="layui-logo">青木良品</div>
            <ul class="layui-nav  layui-layout-left" lay-filter="">
                <li class="layui-nav-item">订单管理</li>
            </ul>
            <ul class="layui-nav layui-layout-right layui-bg-blue">
                <li class="layui-nav-item" th:text="${session.user.name}">
                </li>
                <li class="layui-nav-item"><a href="/mall/user/logout.do">退出</a></li>
            </ul>
        </div>

        <div class="layui-side layui-bg-gray">
            <ul class="layui-nav layui-nav-tree layui-bg-blue" lay-filter="test">
                <!-- 侧边导航: <ul class="layui-nav layui-nav-tree layui-nav-side"> -->
                <li class="layui-nav-item"><a th:href="@{/admin/product/toList.html}">商品管理</a></li>
                <li class="layui-nav-item"><a th:href="@{/admin/activity/toList.html}">活动管理</a></li>
                <li class="layui-nav-item layui-nav-itemed"><a th:href="@{/admin/order/toList.html}">订单管理</a></li>
                <li class="layui-nav-item"><a th:href="@{/admin/user/toList.html}">用户管理</a></li>
            </ul>
        </div>
        <div class="layui-body" style="overflow: hidden;height: 650px">
            <table id="orderList"></table>
        </div>
    </div>
</body>
<script th:src="@{/js/jqurey.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script type="text/javascript">
    layui.use(['element','form','table','layer'], function(){
        var element = layui.element;
        var form = layui.form;
        var layer = layui.layer;
        // 表格渲染
        var table = layui.table
        table.render({
            elem: '#orderList',
            height: 600,
            cols: [ [
                {field: 'id', title: 'ID', width: 110, sort:true},
                {field: 'status', title: '订单状态', width: 110, templet:function (d) {
                    if(d.status=='1'){
                        return '<span>未支付</span>'
                    }else if(d.status=='2'){
                        return '<span>未发货</span>'
                    }else if(d.status=='3'){
                        return '<span>送货中</span>'
                    }else if(d.status=='4'){
                        return '<span>已签收</span>'
                    }else if(d.status=='5'){
                        return '<span>待评价</span>'
                    }else if(d.status=='6'){
                        return '<span>已完成</span>'
                    }else if(d.status=='0'){
                        return '<span>未确认</span>'
                    }
                        return '<span></span>'
                    }},
                {field: 'productname', title: '商品名称', width: 300, templet:function(d){
                    var result=''
                    for(item of d.userOrders){
                        result=result+'<img src="/mall/image/'+item.product.mainImage+'"width=\"80px\" height=\"80px\"> <span style="line-height: 80px">'+item.product.name+'</span><hr>'
                    }
                    return result;
                    }},
                {field: 'price', title: '单价', width: 80, templet:function(d){
                        var result=''
                        for(item of d.userOrders){
                            result=result+'<span style="line-height: 80px">'+item.product.price+'元</span><hr>'
                        }
                        return result;
                    }},
                {field: 'number', title: '数量', width: 60, templet:function(d){
                        var result=''
                        for(item of d.userOrders){
                            result=result+'<span style="line-height: 80px">'+item.number+'</span><hr>'
                        }
                        return result;
                    }},
                {field: 'total', title: '实付款', width: 80, templet:function(d){return '<span>'+d.total+'元</span>';}},
                {field: 'name', title: '收货人', width: 120},
                {field: 'addr', title: '收货地址', width: 220},
                {field: 'opera', title: '操作', width: 100, templet:function (d) {
                    if(d.status=='2')
                        return '<a href="/mall/admin/order/send.do?id='+d.id+'"><button class="layui-btn layui-btn-sm">发货</button></a>'
                     else
                        return ''
                    }},
            ]],
            url: 'list.do',
            // parseData: function (res) {
            //     return{
            //         "msg": res.message, //解析提示文本
            //         "data": res.data, //解析数据列表
            //         "count": res.data.length, //解析数据长度
            //     }
            // }
            response: {
                statusName: 'state' //规定数据状态的字段名称，默认：code
                ,statusCode: 0 //规定成功的状态码，默认：0
                ,msgName: 'message' //规定状态信息的字段名称，默认：msg
                ,dataName: 'data' //规定数据列表的字段名称，默认：data
            }
        })
    });
    $(function () {
        getData(1)
        getData2()
    })
    function getData(pageindex) {
        $.ajax({
            //请求方式
            type : "GET",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url : "list.do",
            //请求成功
            success : function(data) {

            },
            error : function (e) {

            }
        });
    }
    function getData2() {
        $.ajax({
            //请求方式
            type : "GET",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url : "getTotal.do?",
            //请求成功
            success : function(data) {

            },
            error : function (e) {

            }
        });
    }
</script>
</html>